dislikes.userID = null;
dislikes.userLoc = null;
dislikes.usersData = {};
dislikes.totalElements = 1;
dislikes.options = {};
dislikes.friendsData = [];

dislikes.OnNodeInserted = function(context)
{
	if(context == undefined) context = document;
	
	if(dislikes.jQuery('#navItem_di_slik_es', context).length == 0)
	{
		dislikes.jQuery('#bookmarks_menu', context).find('.uiSideNav').prepend('<li class="key-di_slik_es" id="navItem_di_slik_es"><a class="item" href="javascript:void(0);"><span class="imgWrap"><img class="img" src="'+dislikes.getURL("icon14.png")+'" alt=""></span><span class="linkWrap">di.slik.es</span></a></li>');

		dislikes.jQuery('#navItem_di_slik_es', context).click(function()
		{
			dislikes.processRequest({action:'showLoading', callback: 'dislikes.showLoading'}, dislikes.showLoading, context);
			setTimeout(function()
			{
				dislikes.processRequest({action:'getJSON',type:'options', callback: 'dislikes.updateOptionsDialog'}, dislikes.updateOptionsDialog, context);
			}, 500);
		});
	}
	
	
	
	var elArr = dislikes.jQuery('body', context).find('input[name="feedback_params"][isProcessed!=1],input[name="message_id"][isProcessed!=1],span[class*="comment_like_"][isProcessed!=1],#pagelet_fan_count,#pagelet_above_html[isProcessed!=1]');
	elArr.attr('isProcessed', 1);
	
	var procArr = [];
	var procArrGrp = [];
	var procArrComm = [];
	var procArrGrpComm = [];
	var procPagesLike = [];
	
	if(elArr.length > 0)
	{
		dislikes.jQuery(elArr).each(function()
		{
			try
			{	
				if(dislikes.jQuery(this).attr('id') == 'pagelet_above_html')
				{
					if(dislikes.jQuery('#dislikeMainButton', context).length > 0)
						return;
					
					var disArr = dislikes.jQuery('#page_dislike_count', context).attr('currentIDS');
					
					var classAdd = 'hidden_elem ';
					var text = '';
					
					if(disArr != undefined)
					{
						var checkArr = disArr.split(',');
						if(dislikes.jQuery.inArray(dislikes.userID, checkArr) == -1)
						{
							var text = dislikes.getMessage('DislikeThis');
							var classAdd = '';
						}
						else
						{
							var text = dislikes.getMessage('NotDislikeThis');
							var classAdd = '';
						}
					}
					
					dislikes.jQuery('.profileHeaderMain > .fbProfileByline', context).before('<label class="'+classAdd+'mlm mainButton uiButton" id="dislikeMainButton"><img class="img" style="width: 15px; display: inline-block; height: 11px;" src="'+dislikes.getURL("icon14.png")+'" /><input value="'+text+'" type="button" style="margin-left: 5px;" id="dislike_page_button"></label>');
					
					dislikes.jQuery('#dislikeMainButton', context).click(function()
					{
						dislikes.addPageVote(context);					
					});
					
					
					return;
				}				
				else if(dislikes.jQuery(this).attr('id') == 'pagelet_fan_count')
				{
					if(dislikes.jQuery('#page_dislike_count', context).length > 0)
						return;
					
					var tmpUrl = dislikes.jQuery('#pagelet_footer_actions', context).find('a:last').attr('href');
					var pos0 = tmpUrl.indexOf('p[]=');
					//var pos1 = tmpUrl.indexOf('"', pos0);
					var appid = 'page_'+tmpUrl.slice(pos0+4); 
					
					var html = dislikes.jQuery(this).html();
					dislikes.jQuery(this).append(html);
					dislikes.jQuery(this).children('div:last').addClass('hidden_elem').html(dislikes.HTMLParser('<div><span id="page_dislike_count" class="uiNumberGiant fsxxl fwb"></span></div>'+dislikes.getMessage('PeopleDislikeThis')));
					dislikes.jQuery(this).find('#page_dislike_count').attr('pageid', appid).css('overflow', 'hidden');
					dislikes.jQuery(this).children('div:last').children().css('overflow', 'hidden');
					
					procPagesLike.push(appid);
					
					return;
				}
				
				if(dislikes.jQuery(this).attr('class').indexOf('comment_like_') != -1)
					var tmp = dislikes.jQuery(this).children('button').val();
				else
					var tmp = dislikes.jQuery(this).val();
				
				if(typeof(tmp) == 'undefined' || tmp == 0) return;
				
				if(dislikes.jQuery(this).attr('name') == 'message_id')
				{
					tmp = tmp + '_' + dislikes.jQuery(this).siblings('input[name="gid"]').val();
					procArrGrp.push(tmp);
					var isGrp = true;
					
					dislikes.jQuery(this).closest('form').attr('isGroup', 1);
				}
				else if(dislikes.jQuery(this).attr('class').indexOf('comment_like_') != -1)
				{
					var isComment = true;
					if(dislikes.jQuery(this).closest('form').children('input[name="gid"]').length > 0)
					{
						var isGrp = true;
						tmp = 'commGrp_'+tmp + '_' + dislikes.jQuery(this).closest('form').children('input[name="gid"]').val();
						
						procArrGrpComm.push(tmp);
					}
					else if(dislikes.jQuery(this).closest('form').children('input[name="feedback_params"]').length > 0)
					{
						var paramFbid = dislikes.jQuery(this).closest('form').children('input[name="feedback_params"]').val();
						if(typeof(paramFbid) == 'undefined') return;
						var obj = JSON.parse(paramFbid);
						if(typeof(obj.target_fbid) == 'undefined') return;				
						tmp = 'comm_'+tmp+'_'+obj.target_fbid;
						
						procArrComm.push(tmp);
					}
					else
					{
						return;
					}
					
					if(dislikes.jQuery(this).parent().attr('id').indexOf('dislikeForm') != -1)
						return;
				}
				else
				{
					var obj = JSON.parse(tmp);
					var fbid = obj.target_fbid;
					
					if(typeof(fbid) == 'undefined')
						return;
					
					procArr.push(fbid);
					var isGrp = false;
					
					dislikes.jQuery(this).closest('form').attr('isGroup', 0);
				}
				
				var html = '<span class="dislikeCont hidden_elem"> · <button class="dislike_link hide stat_elem as_link" title="'+dislikes.getMessage('DislikeDescription')+'" type="submit" name="dislike"><span class="default_message">'+dislikes.getMessage('DislikeThis')+'</span><span class="default_message">'+dislikes.getMessage('NotDislikeThis')+'</span></button></span>';
				
				if(isComment)
					dislikes.jQuery(this).parent().append(html);
				else
					dislikes.jQuery(this).parent().find('button.as_link:first').after(html);
					
					
				
				
				dislikes.jQuery(this).parent().find('button.dislike_link').click(function(event)
				{
					dislikes.dislikeClicked(event, context);
					return false;
				});
				
				if(isGrp)
				{
					var myEl = dislikes.jQuery(this).parent().find('.mall_ufi_like:first');
				}
				else
				{
					var myEl = dislikes.jQuery(this).parent().find('.uiUfiLike:first');
				}
				
				if(isComment)
				{
					dislikes.jQuery(this).parent().find('.dislikeCont').after('<span class="dislikeCount hidden_elem"> · <i class="img" style="width: 14px;display: inline-block;height: 9px;background-image: url('+dislikes.getURL("icon9.png")+');background-repeat: no-repeat;"></i><a class="uiTooltip comment_like_button"><span class="uiTooltipHeader" style="color: #C20000"></span><span class="uiTooltipWrap bottom center centerbottom"><span class="uiTooltipText"></span></span></a></span>');
				}
				else
					myEl.after('<li class="hidden_elem uiUfiLike ufiItem uiListItem  uiListVerticalItemBorder uiDislike"><div class="UIImageBlock clearfix"><a class="UIImageBlock_Image UIImageBlock_ICON_Image" tabindex="-1"><label class="dislikeButton"><i class="img" style="width: 20px; height: 14px;background-image: url('+dislikes.getURL("icon14.png")+');background-repeat: no-repeat;"></i></label></a><div class="UIImageBlock_Content UIImageBlock_ICON_Content"></div></div></li>');
				
				dislikes.jQuery(this).find('.dislikeButton').click(function(event){ dislikes.dislikeClicked(event, context); });
			
			}
			catch(e)
			{
				//alert(e);
			}
		});
		
		dislikes.nodesCount(context, procArr, procArrGrp, procArrComm, procArrGrpComm, procPagesLike);
	}
};

dislikes.showLoading = function(r, context)
{
	if(context == undefined) context = document;
	
	var r = r.replace(/__LOADING__/g, dislikes.getMessage('Loading'));
	dislikes.jQuery('#content', context).find('.generic_dialog').remove();
	dislikes.jQuery('#content', context).append(r);	
	dislikes.jQuery('#content', context).find('.generic_dialog').css('top', context.defaultView.pageYOffset+100);
};

dislikes.openDislikes = function(e, context)
{
	var target = dislikes.jQuery(( e.srcElement? e.srcElement : e.target));
	
	dislikes.processRequest({action:'showLoading', callback: 'dislikes.showLoading'}, dislikes.showLoading, context);
	setTimeout(function(){
		dislikes.processRequest({action:'getJSON',type:'dislikeList', ids: target.attr('dislikeIds'), callback: 'dislikes.updateDislikeList'}, dislikes.updateDislikeList, context);
	}, 500);
};

dislikes.openMutualDislikes = function(e, context)
{
	var target = dislikes.jQuery(( e.srcElement? e.srcElement : e.target));
	
	dislikes.processRequest({action:'showLoading', callback: 'dislikes.showLoading'}, dislikes.showLoading, context);
	setTimeout(function(){
		dislikes.processRequest({action:'getJSON',type:'dislikeList', ids: target.attr('dislikeIds'), callback: 'dislikes.updateDislikeList'}, dislikes.updateDislikeList, context);
	}, 500);
};

dislikes.updateDislikeList = function(r, context)
{
	if(context == undefined) context = document;

	var el = dislikes.jQuery('#content', context).find('.generic_dialog:first').find('.pop_content');
	var r = r.replace(/__DISLIKE_LIST__/g, dislikes.getMessage('PeopleWhoDislikeThis'));
	
	var res = dislikes.jQuery(dislikes.HTMLParser(r));
	var mylist = res.find('ul');

	var listitems = mylist.children('li').css('padding', '4px').get();
	listitems.sort(function(a, b)
	{
		var compA = dislikes.jQuery(a).text().toUpperCase();
		var compB = dislikes.jQuery(b).text().toUpperCase();
		return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
	});
	
	res.find('ul').html(listitems);
	res.find('.fbListOverflow').css({"overflow-y":"auto","max-height":"353px","height":"353px" });
	var str = res.children().html();	
	el.html(str);
	dislikes.jQuery(el).find('.dialog_buttons').find('input').click(function(){ dislikes.jQuery(this).closest('.generic_dialog').remove(); });
};

dislikes.updateOptionsDialog = function(r, context)
{
	if(context == undefined) context = document;
	
	var el = dislikes.jQuery('#content', context).find('.generic_dialog:first').find('.pop_content');
	var r = r.replace(/__OPTIONS__/g, 'di.slik.es - '+dislikes.getMessage('Options'));
	
	var res = dislikes.jQuery(dislikes.HTMLParser(r));
	
	var langOpts = '';
	for(var loc in dislikes.trans)
	{
		langOpts += '<option value="'+loc+'">'+dislikes.trans[loc].name+'</option>';
	}
	
	var html = dislikes.jQuery(dislikes.HTMLParser('<div><div id="dislikesOptionsIcon"><img src="'+dislikes.getURL("icon48.png")+'"></div><div class="fbDislikeMargin"><label>'+dislikes.getMessage('SelectLanguage') +'</label><br /><select id="dislikes_options_language"><option value="0" selected="selected">'+dislikes.getMessage('UseFacebookLanguage')+'</option>'+langOpts+'</select><br /><br />'+dislikes.getMessage('ReloadAfterChange')+'</div><div class="fbDislikeMargin"><label>'+dislikes.getMessage('PostRandomComment') +'</label><br /><input type="radio" value="1" name="dislikes_options_comment" /> '+dislikes.getMessage('Yes')+' <input type="radio" name="dislikes_options_comment" value="0" checked="checked" />'+dislikes.getMessage('No')+'</div><div class="fbDislikeMargin"><label>'+dislikes.getMessage('DoYouWantDislikesToPostInfoAboutYourDislikesToYourWall') +'</label><br /><input type="radio" value="1" name="dislikes_options_postInfoToWall" /> '+dislikes.getMessage('Yes')+' <input type="radio" name="dislikes_options_postInfoToWall" value="0" checked="checked" />'+dislikes.getMessage('No')+'</div><div class="fbDislikeMargin"><table align="center" width="90%" border="0" cellspacing="5" cellpading="0"><tr><td colspan="2" align="center">Please donate Bitcoins to:<br /><strong>17a2oPp89RXjNQpmpvsDSZKhKuXHTcvMiR</strong><br /><br /><a href="http://www.bitcoin.org" target="_blank"><img src="'+dislikes.getURL('bitcoin.png')+'" /></a></td></tr><tr><td width="50%" align="center"><form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----"><input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online."><img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/pl_PL/i/scr/pixel.gif" width="1" height="1"></form></td><td width="50%" align="center"><a name="fb_share" target="_blank" type="button" share_url="http://di.slik.es" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fdi.slik.es&amp;src=sp"><img src="'+dislikes.getURL('share_facebook.png')+'" /></a></td></tr><tr><td colspan="2"><a href="http://di.slik.es/" target="_blank">di.slik.es</a></td></tr></table></div></div>'));
	
	res.find('.uiList').html(html);
	res.find('.fbDislikeMargin').css({"margin": "15px"});
	res.find('.fbDislikeMargin:last').css({"text-align": "center", "margin": "10px", "margin-top": "0", "margin-bottom": "0"});
	res.find('.fbDislikeMargin:last').find('td').css({"text-align": "center"});
	
	res.find('.fbListOverflow').css({"overflow-y":"auto","max-height":"333px","height":"333px" });
	var str = res.html();
	el.html(str);
	
	el.find('#dislikesOptionsIcon').css({"position": "absolute", "top": "50px", "right": "25px"});
	
	el.find('#dislikes_options_language').children('option[value="'+dislikes.options.language+'"]').attr('selected', true);
	el.find('#dislikes_options_language').children('option[value="'+dislikes.options.language+'"]').siblings().removeAttr('selected');
	
	el.find('input[name="dislikes_options_comment"][value="'+dislikes.options.commentStuff+'"]').attr('checked',  true);
	el.find('input[name="dislikes_options_comment"][value="'+dislikes.options.commentStuff+'"]').siblings().removeAttr('checked');
	
	el.find('input[name="dislikes_options_postInfoToWall"][value="'+dislikes.options.postInfoToWall+'"]').attr('checked',  true);
	el.find('input[name="dislikes_options_postInfoToWall"][value="'+dislikes.options.postInfoToWall+'"]').siblings().removeAttr('checked');
	
	
	if(dislikes.options.firstTime == 1)
	{
		var newOptions = {};		
		//newOptions.language = el.find('#dislikes_options_language').children('option:selected').val();
		newOptions.language = el.find('#dislikes_options_language').children('option:selected')[0].value;
		newOptions.commentStuff = el.find('input[name="dislikes_options_comment"]:checked').val();
		newOptions.postInfoToWall = el.find('input[name="dislikes_options_postInfoToWall"]:checked').val();
		newOptions.firstTime = 0;		
		dislikes.options = dislikes.jQuery.extend({}, newOptions);		
		dislikes.processRequest({action:'saveOptions', userID: dislikes.userID, options: newOptions, callback: ''}, function(){}, context);
	}
	
	el.find('.dialog_buttons').find('input').click(function()
	{
		var newOptions = {}
		//newOptions.language = el.find('#dislikes_options_language').children('option:selected').val();
		newOptions.language = el.find('#dislikes_options_language').children('option:selected')[0].value;
		newOptions.commentStuff = el.find('input[name="dislikes_options_comment"]:checked').val();
		newOptions.postInfoToWall = el.find('input[name="dislikes_options_postInfoToWall"]:checked').val();
		newOptions.firstTime = 0;
		dislikes.options = dislikes.jQuery.extend({}, newOptions);
		dislikes.processRequest({action:'saveOptions', userID: dislikes.userID, options: newOptions, callback: ''}, function(){}, context);
		
		dislikes.jQuery(this).closest('.generic_dialog').remove()
	});
};

dislikes.addDislikesToThePage = function(r)
{
	if(typeof(r) == 'string')
		r = JSON.parse(r);
	
	if(typeof(r.doc) == 'undefined')
	{
		r.doc = document;
	}
	
	var context = r.doc;
	if(context == undefined) context = document;
	
	dislikes.usersData = r.usersData;
	
	dislikes.jQuery('input[name="feedback_params"][isProcessed=1],input[name="message_id"][isProcessed=1],span[class*="comment_like_"][isProcessed=1],#pagelet_fan_count[isProcessed=1],#pagelet_above_html[isProcessed=1]', context).each(function(k,v)
	{
		var paramTmp = 	dislikes.jQuery(this).val();
		
		var isComment = false;
		var isPage = false;
		
		if(dislikes.jQuery(this).attr('id') == 'pagelet_above_html')
		{
			return;
		}
		else if(dislikes.jQuery(this).attr('id') == 'pagelet_fan_count')
		{
			var fbid = dislikes.jQuery('#page_dislike_count', context).attr('pageid');
			isPage = true;
		}
		else if(dislikes.jQuery(this).attr('name') == 'message_id')
		{
			var fbid = paramTmp+'_'+dislikes.jQuery(this).siblings('input[name="gid"]').val();
		}
		else if(dislikes.jQuery(this).attr('class').indexOf('comment_like_') != -1)
		{
			var paramTmp = 	dislikes.jQuery(this).children('button').val();
			
			if(dislikes.jQuery(this).closest('form').children('input[name="gid"]').length > 0)
			{
				var fbid = 'commGrp_'+paramTmp+'_'+dislikes.jQuery(this).closest('form').children('input[name="gid"]').val();
			}
			else if(dislikes.jQuery(this).closest('form').children('input[name="feedback_params"]').length > 0)
			{
				var paramFbid = dislikes.jQuery(this).closest('form').children('input[name="feedback_params"]').val();
				if(typeof(paramFbid) == 'undefined') return;
				var obj = JSON.parse(paramFbid);
				if(typeof(obj.target_fbid) == 'undefined') return;				
				var fbid = 'comm_'+paramTmp+'_'+obj.target_fbid;
			}
			else
			{
				return;
			}
			isComment = true;
		}
		else
		{
			if(typeof(paramTmp) == 'undefined') return;
			var obj = JSON.parse(paramTmp);
			var fbid = obj.target_fbid;
		}
		
		if(typeof(r[fbid]) != 'undefined')
		{
			if(isComment)
			{
				dislikes.totalElements += 1;				
				r[fbid].id = dislikes.jQuery(this).parent().attr('id', 'dislikeForm'+dislikes.totalElements).attr('id');
				r[fbid].isComment = true;
				r[fbid].doc = context;
				dislikes.updateDislike(r[fbid]);
			}
			else if(isPage)
			{
				dislikes.totalElements += 1;				
				r[fbid].id = dislikes.jQuery(this).children('div:last').attr('id', 'dislikeForm'+dislikes.totalElements).attr('id');
				r[fbid].isComment = true;
				r[fbid].doc = context;
				dislikes.updatePage(r[fbid]);
			}
			else
			{
				dislikes.totalElements += 1;
				r[fbid].id = dislikes.jQuery(this).closest('form').attr('id', 'dislikeForm'+dislikes.totalElements).attr('id');
				r[fbid].isComment = false;
				r[fbid].doc = context;
				dislikes.updateDislike(r[fbid]);
			}
		}
	});
};

dislikes.addPageVote = function(context)
{
	if(context == undefined) context = document;
	
	var fbid = dislikes.jQuery('#page_dislike_count', context).attr('pageid');
	
	var elID 	= 'page_dislike_count';
	var disArr  = dislikes.jQuery('#page_dislike_count', context).attr('currentIDS');
	
	var checkArr = disArr.split(',');
	
	var opt = (dislikes.jQuery.inArray(dislikes.userID, checkArr) == -1 ? 'add' : 'remove');
	var res = {error: false, curFbid: fbid, id: elID, opt: opt, doc: context}
	
	dislikes.updatePage(res);
	
	dislikes.processRequest({action:'getJSON',type:'addVote' ,fbid: fbid, elid: elID, opt: opt, target: -1, callback: 'dislikes.updatePage'}, dislikes.updatePage, context);
};

dislikes.dislikeClicked = function(e, context)
{
	if(context == undefined) context = document;
	
	var el = dislikes.jQuery(( e.srcElement? e.srcElement : e.target));
	var clForm = el.closest('form');
	
	if(el.closest('[id^="dislikeForm"]').hasClass('commentActions'))
	{
		var cid = el.closest('[id^="dislikeForm"]').children('span:first').children('button').val();
		
		if(el.closest('form').attr('isGroup') == 1)
		{
			var tmp = clForm.children('input[name="gid"]').val();
			var type = 'commGrp';
		}
		else
		{
			var tmpX = el.closest('form').find('input[name="feedback_params"]').val();
			var obj = JSON.parse(tmpX);
			var tmp = obj.target_fbid;
			var type = 'comm';
		}
		var target = -1;
		var fbid = type+'_'+cid+'_'+tmp;
		var isComment = true;
	}
	else if(el.closest('form').attr('isGroup') == 1)
	{
		var fbid = clForm.children('input[name="message_id"]').val()+'_'+clForm.children('input[name="gid"]').val();
		var target = -1;
	}
	else
	{
		var tmp = el.closest('form').find('input[name="feedback_params"]').val();
		var obj = JSON.parse(tmp);
		var fbid = obj.target_fbid;
		var target = obj.actor;
	}
	
	if(isComment)
	{
		var elID 	= el.closest('[id^="dislikeForm"]').attr('id');
		var disArr  = el.closest('[id^="dislikeForm"]').attr('currentIDS');
	}
	else
	{
		var elID 	= clForm.attr('id');
		var disArr  = clForm.attr('currentIDS');
	}
	
	var checkArr = disArr.split(',');
	
	var opt = (dislikes.jQuery.inArray(dislikes.userID, checkArr) == -1 ? 'add' : 'remove');
	var res = {error: false, curFbid: fbid, id: elID, opt: opt, doc: context}
	
	if(isComment)
		res.isComment = true;
	
	dislikes.updateDislike(res);
	
	dislikes.processRequest({action:'getJSON',type:'addVote' ,fbid: fbid, elid: elID, opt: opt, target: target, callback: 'dislikes.updateDislike'}, dislikes.updateDislike, context);
};

dislikes.updatePage = function(r)
{
	var context = r.doc;
	
	if(context == undefined)
		context = document;
	
	var id = r.id;
	var el2 = dislikes.jQuery('#'+id, context);
	var el = dislikes.jQuery('#page_dislike_count', context);
	
	if(r.commentOnly)
	{
		var commParams = {};
		
		commParams.post_form_id = dislikes.jQuery('body', context).find('input[name=post_form_id]').val();
		commParams.fb_dtsg = dislikes.jQuery('body', context).find('input[name=fb_dtsg]').val();
		commParams.user_id = dislikes.userID;
		commParams.page_id = dislikes.jQuery('#page_dislike_count', context).attr('pageid');
		
		var objTest = true;
		for(var id in commParams)
		{
			if(commParams[id] == undefined)
			{
				objTest = false;
				break;
			}
		}
		
		if(objTest)
		{
			dislikes.processRequest({action:'postStatus', commParams: commParams, commMessage: dislikes.getMessage('randomComment', 2), callback:''}, function(){}, context);
		}
		return;
	}
	
	if(typeof(r.error) != 'undefined')
	{
		if(r.error == true)
		{
			var opt = (r.opt == 'add' ? 'remove' : 'add');
		}
		else
		{
			var opt = r.opt;
		}
		
		var curIdsArr = el.attr('currentIDS');
		if(curIdsArr == '')
			var oldArr = [];
		else
			var oldArr = curIdsArr.split(',');
		
		if(opt == 'add')
			oldArr.push(dislikes.userID);
		else
		{
			var idx = oldArr.indexOf(dislikes.userID);
			if(idx != -1)
			{
				oldArr.splice(idx, 1);
			}
		}
		r.uids = oldArr;
		r.count = oldArr.length;
	}
	
	el.text(r.uids.length);
	
	var allIDS = r.uids.join();	
	el.attr('currentIDS', allIDS);
	
	el2.removeClass('hidden_elem').css('color', 'red');
	
	if(dislikes.jQuery.inArray(dislikes.userID, r.uids ) == -1)
	{
		var text = dislikes.getMessage('DislikeThis');
	}
	else
	{
		var text = dislikes.getMessage('NotDislikeThis');
	}
	
	var list = '';
	var add = 0;
	var mutArr = [];
	
	for(var i = 0; i < r.uids.length ; i++)
	{
		if(dislikes.jQuery.inArray(r.uids[i], dislikes.friendsData) != -1)
		{
			if(add < 8)
				list += '<li class="uiFacepileItem uiListItem  uiListHorizontalItemBorder uiListHorizontalItem"><a class="uiTooltip link" href="http://www.facebook.com/profile.php?id='+r.uids[i]+'" data-jsid="anchor"><img class="uiProfilePhoto uiProfilePhotoMedium img" src="http://graph.facebook.com/'+r.uids[i]+'/picture" alt="" data-jsid="img"><span class="uiTooltipWrap top left lefttop"><span class="uiTooltipText">'+dislikes.usersData[r.uids[i]]+'</span></span></a></li>';
			mutArr.push(r.uids[i]);
			add++;
		}
	}
	
	if(dislikes.jQuery('#dislikes_mutual', context).length == 0 && add > 0)
	{
		var html = dislikes.jQuery(dislikes.HTMLParser('<li id="dislikes_mutual" class="uiListItem  uiListVerticalItemBorder"><div class="uiFacepile uiFacepileMedium pvs"><ul class="uiList uiListHorizontal clearfix">'+list+'</ul></div></li><li class="pts inCommonSectionList uiListItem  uiListVerticalItemBorder"><div class="UIImageBlock clearfix"><img class="img" src="'+dislikes.getURL("icon14.png")+'" alt=""> <span class="visible"><a id="dislikes_mutual_click" href="javascript:void(0);" dislikeIds="'+mutArr.join(',')+'">'+add+' friends dislike this.</a></span></div></li>'));
		
		dislikes.jQuery(context).find('#pagelet_mutual').find('.uiList:first').append(html.html());
		
		dislikes.jQuery('#dislikes_mutual_click', context).click(function(e)
		{
			dislikes.openMutualDislikes(e, context);
		});
	}
	
	dislikes.jQuery('#dislikeMainButton', context).removeClass('hidden_elem').find('input').val(text);
}

dislikes.updateDislike = function(r)
{
	var context = r.doc;
	
	if(context == undefined)
		context = document;
	
	var id = r.id;
	var el = dislikes.jQuery('#'+id, context);
	
	if(typeof(r.error) != 'undefined')
	{
		if(r.error == true)
		{
			var opt = (r.opt == 'add' ? 'remove' : 'add');
		}
		else
		{
			var opt = r.opt;
		}
		
		var curIdsArr = el.attr('currentIDS');
		if(curIdsArr == '')
			var oldArr = [];
		else
			var oldArr = curIdsArr.split(',');
			
			
		if(opt == 'add')
			oldArr.push(dislikes.userID);
		else
		{
			var idx = oldArr.indexOf(dislikes.userID);
			if(idx != -1)
			{
				oldArr.splice(idx, 1);
			}
		}
		//join poszukac
		r.uids = oldArr;
		r.count = oldArr.length;
	}
	
	if(r.commentOnly)
	{
		if(typeof(r.commentCnt) == 'undefined' || r.commentCnt > 0)
			return true;
		
		var commParams = {};
		
		if(el.attr('isGroup') == 1)
		{}
		else
		{
			commParams.feedback = dislikes.jQuery(el).find('input[name="feedback_params"]').val();
			commParams.link_data = dislikes.jQuery(el).closest('[data-ft]').attr('data-ft');
		}
		commParams.post_form_id = dislikes.jQuery(el).find('input[name=post_form_id]').val();
		commParams.fb_dtsg = dislikes.jQuery(el).find('input[name=fb_dtsg]').val();
		commParams.charset_test = dislikes.jQuery(el).find('input[name=charset_test]').val();
		commParams.fbid = r.curFbid;
		
		var objTest = true;
		for(var id in commParams)
		{
			if(commParams[id] == undefined)
			{
				objTest = false;
				break;
			}
		}
		
		if(objTest)
		{
			dislikes.processRequest({action:'commentPost', commParams: commParams, commMessage: dislikes.getMessage('randomComment'), callback:''}, function(){}, context);
		}
		return true;
	}
	
	var allIDS = r.uids.join();	
	el.attr('currentIDS', allIDS);
	
	el.find('.dislike_link:first').parent().removeClass('hidden_elem');
	
	var text = '';

	var startCount = r.count;
	
	if(r.count > 0)
	{
		if(r.isComment)
			el.find('.dislikeCount:last').removeClass('hidden_elem');
		else
			el.removeClass('collapsed_comments').removeClass('hidden_acc_comment').find('.uiUfiLike:last').removeClass('hidden_elem');
	}
	else
	{
		if(r.isComment)
			el.find('.dislikeCount:last').addClass('hidden_elem');
		else
			el.find('.uiUfiLike:last').addClass('hidden_elem');
	}

	var j = 0;
	
	var iLike = false;
	
	if(dislikes.jQuery.inArray(dislikes.userID, r.uids ) != -1)
	{
		el.attr('isDisliked', 1);
		el.find('.dislike_link:first').attr('title', dislikes.getMessage('NotDislikeDescription')).find('span.default_message:first').hide().parent().find('span.default_message:last').show();
		el.find('.dislikeButton:first').css('cursor', 'default !important');
		
		iLike = true;
		
		if(r.count == 1)
		{
			text += dislikes.getMessage('YouDislikeThisSentence');
			
			if(r.isComment)
			{
				var tstEl = el.find('.dislikeCount:last');
				
				tstEl.children('a').children('span.uiTooltipHeader').attr('dislikeIds', allIDS).html( dislikes.getMessage('people_string', startCount) );
				
				var tmpTxt = dislikes.jQuery(dislikes.HTMLParser(text));
				tstEl.find('.uiTooltipText').html(tmpTxt.text());		
			}
			else
				el.find('.uiUfiLike:last').find('.UIImageBlock_Content').html(text);
			
			return;
		}
		else
		{
			text += dislikes.getMessage('You')+', ';
		}
		r.count--;
		j++;
	}
	else
	{
		el.removeAttr('isDisliked');
		el.find('.dislike_link:first').attr('title', dislikes.getMessage('DislikeDescription')).find('span.default_message:last').hide().parent().find('span.default_message:first').show();
		el.find('.dislikeButton:first').css('cursor', 'pointer');
	}
	
	if(r.count > 0)
	{
		dislikes.jQuery(r.uids).each(function(k,v)
		{
			if(j == 2)
				return false;
			
			if(v != dislikes.userID)
			{
				text+= ' <a href="https://www.facebook.com/profile.php?id='+v+'"> '+dislikes.usersData[v]+'</a>, ';
				
				r.count--;
				j++;
			}
		});
		text = text.slice(0, -2);
	}
	
	if(r.count > 0)
	{
		var text2 = (iLike ? dislikes.getMessage('YouAndOtherDislikeThisSentence') : dislikes.getMessage('OtherDislikeThisSentence'));
		
		var tmpStr = dislikes.getMessage('OtherPeople');
		
		var otherStr  = (tmpStr.indexOf('__CNT__') == -1 ? tmpStr +' ('+(r.count)+')' : tmpStr.replace('__CNT__', r.count));
		text += ' '+dislikes.getMessage('And')+' <a class="displayDislikesList" dislikeIds="'+allIDS+'" href="javascript:void(0);">'+otherStr+'</a> '+text2;
	}
	else
	{
		var pos1 = text.lastIndexOf(',');
		if(pos1 != -1)
		{
			var tmp = text.slice(0, pos1);
			var tmp2 = text.slice(pos1+1);
			var text2 = (iLike ? dislikes.getMessage('YouAndOtherDislikeThisSentence') : dislikes.getMessage('OtherDislikeThisSentence'));
			text = tmp + ' '+dislikes.getMessage('And')+' '+tmp2+' '+text2;
		}
		else
		{
			text += ' '+dislikes.getMessage('OtherOnePersonDislike');
		}
	}
	
	if(r.isComment)
	{
		var tstEl = el.find('.dislikeCount:last');
		
		tstEl.children('a').children('span.uiTooltipHeader').attr('dislikeIds', allIDS).html( dislikes.getMessage('people_string', startCount) );
		
		var tmpTxt = dislikes.jQuery(dislikes.HTMLParser(text));
		tstEl.find('.uiTooltipText').html(tmpTxt.text());		
	}
	else
		el.find('.uiUfiLike:last').find('.UIImageBlock_Content').html(text);
};

dislikes.nodesCount = function(context, newIds, newIds2, newIds3, newIds4, appIds)
{
	if(newIds.length + newIds2.length + newIds3.length + newIds4.length + appIds.length > 0)
	{
		dislikes.processRequest({action:'getJSON',type:'dislikes', ids: newIds,  grpIDS: newIds2, commIDS: newIds3, grpCommIDS: newIds4, pageIds: appIds, callback: 'dislikes.addDislikesToThePage'}, dislikes.addDislikesToThePage, context);
	}
};

dislikes.addFacebookIframe = function(d, context)
{
	if(context == undefined) context = document; // chrome & safari	
	dislikes.jQuery('body', context).append(d);
};

dislikes.DOMstartup = function(context)
{
	if(context == undefined) context = document; // chrome & safari
	
	try
	{
		var data2 = context.body.parentNode.innerHTML;
		var pos1 = data2.indexOf('Env={')+4;
		if(pos1 == -1) return;
		
		var pos2 = data2.indexOf('user:', pos1)+5;
		if(pos2 == -1) return;
		
		var pos3 = data2.indexOf(',', pos2);
		
		dislikes.userID = data2.slice(pos2, pos3).toString();
		
		
		var pos4 = data2.indexOf('locale:', pos1)+7;
		var pos5 = data2.indexOf(',', pos4);
		
		dislikes.processRequest({action:'loadOptions', userID: dislikes.userID, callback: 'dislikes.finishStartup'}, dislikes.finishStartup, context);
		dislikes.userLoc = data2.slice(pos4+1, pos5-1).toString();
	}
	catch(e)
	{
		//console.log(e);
	}
};

dislikes.finishStartup = function(options, context)
{
	if(context == undefined) context = document; // chrome & safari
	
	dislikes.trans = dislikes.jQuery.extend({}, options.trans);
	delete(options.trans);
	
	dislikes.friendsData = options.friends;
	delete(options.friends);
	
	
	dislikes.options = dislikes.jQuery.extend({}, options);
	
	if(dislikes.options.firstTime == 1)
	{
		dislikes.processRequest({action:'showLoading', callback: 'dislikes.showLoading'}, dislikes.showLoading, context);
		setTimeout(function()
		{
			dislikes.processRequest({action:'getJSON',type:'options', callback: 'dislikes.updateOptionsDialog'}, dislikes.updateOptionsDialog, context);
		}, 500);
	}
	
	dislikes.jQuery('body', context).live('DOMNodeInserted', function(){ setTimeout(function() { dislikes.OnNodeInserted(context); },500)}, false);
	dislikes.jQuery('body', context).append('<span></span>');
	dislikes.jQuery('.displayDislikesList', context).live('click',function(event){ dislikes.openDislikes(event, context); }, false);
	dislikes.jQuery('.uiTooltipHeader', context).live('click', function(event){ dislikes.openDislikes(event, context); }, false);

};